// Copyright Epic Games, Inc. All Rights Reserved.

#include "LyraTeamPublicInfo.h"

#include "Net/UnrealNetwork.h"
#include "Teams/LyraTeamInfoBase.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraTeamPublicInfo)

class FLifetimeProperty;

/**
 * 构造函数
 */
ALyraTeamPublicInfo::ALyraTeamPublicInfo(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
}

/**
 * 获取生命周期复制属性
 */
void ALyraTeamPublicInfo::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps); // 调用父类方法

	DOREPLIFETIME_CONDITION(ThisClass, TeamDisplayAsset, COND_InitialOnly); // 条件复制团队显示资源（仅初始）
}

/**
 * 设置团队显示资源
 */
void ALyraTeamPublicInfo::SetTeamDisplayAsset(TObjectPtr<ULyraTeamDisplayAsset> NewDisplayAsset)
{
	check(HasAuthority()); // 检查是否有权限
	check(TeamDisplayAsset == nullptr); // 检查当前显示资源为空

	TeamDisplayAsset = NewDisplayAsset; // 设置团队显示资源

	TryRegisterWithTeamSubsystem(); // 尝试注册到团队子系统
}

/**
 * 当团队显示资源复制时调用
 */
void ALyraTeamPublicInfo::OnRep_TeamDisplayAsset()
{
	TryRegisterWithTeamSubsystem(); // 尝试注册到团队子系统
}